class TypeController < ApplicationController
layout "admin"
before_filter :login_required, :only => [:new,:create,:edit,:update,:destroy,:list,:index,:show]
before_filter :initvars

  def index
    list
    render :action => 'list'
  end

  def list
    @types = Type.paginate :page => params[:page], :per_page => 20
  end

  def show
    @type = Type.find(params[:id])
  end

  def new
    @type = Type.new
  end

  def create
    @type = Type.new(params[:type])
    if @type.save
      flash[:notice] = 'Type was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @type = Type.find(params[:id])
  end

  def update
    @type = Type.find(params[:id])
    if @type.update_attributes(params[:type])
      flash[:notice] = 'Type was successfully updated.'
      redirect_to :action => 'show', :id => @type
    else
      render :action => 'edit'
    end
  end

  def destroy
    Type.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
